//
//  BindingPhoneViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/7/20.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "BindingPhoneViewController.h"
#import "BinDingTextView.h"
#import "UIButton+Timer.h"

@interface BindingPhoneViewController ()
{
    BinDingTextView*shoujihaoView;
    NSString*validationStr;
    UITextField*validationText;
}
@end

@implementation BindingPhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=LRRGBColor(235, 240, 242);
    self.title=@"绑定手机";
    [self setUI];
}
-(void)setUI
{
    shoujihaoView=[[BinDingTextView alloc]initWithFrame:CGRectMake(0, 74, width_screen, 45)];
    shoujihaoView.textField.placeholder=@"输入手机号";
    shoujihaoView.titleLab.text=@"手机号码";
    [self.view addSubview:shoujihaoView];
    // 验证码
    validationText=[[UITextField alloc]initWithFrame:CGRectMake(0, 120, width_screen, 45)];
    validationText.backgroundColor=[UIColor whiteColor];
    validationText.placeholder=@"验证码";
    validationText.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)] ;
    validationText.leftView.userInteractionEnabled = NO;
    validationText.font=[UIFont systemFontOfSize:13];
    validationText.leftViewMode = UITextFieldViewModeAlways;
    [self.view addSubview:validationText];
    
    //倒计时
    UIButton*timerButton=[UIButton buttonWithType:UIButtonTypeCustom];
    timerButton.frame=CGRectMake(width_screen-110, 129, 100, 25);
    timerButton.backgroundColor=[UIColor whiteColor];
    timerButton.layer.cornerRadius=3;
    timerButton.layer.borderWidth=1;
    timerButton.layer.borderColor=LRRGBColor(22, 141, 210).CGColor;
    [timerButton setTitleColor:LRRGBColor(22, 141, 210) forState:0];
    timerButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [timerButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [timerButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:timerButton];
    
    //确认按钮
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor=LRRGBColor(23, 146, 211);
    button.layer.cornerRadius=5;
    
    button.frame=CGRectMake(20, 200, width_screen-40, 45);
    [button setTitle:@"确定" forState:0];
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    
}

//验证码
-(void)validationRequest
{
    
    [HTTPURL postRequest:LINK_BASE_URL(@"register/generateValidation.api") parameters:@{@"phone":shoujihaoView.textField.text} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        validationStr=responseObject[@"data"];
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
//倒计时
- (void)buttonAction:(UIButton *)button
{  [self validationRequest];
    button.time = 10;
    button.format = @"%ld秒后重试";
    [button startTimer];
}
//确认
-(void)buttonClick
{

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
